package com.ruoyi.web.controller.bus.controller;

import com.ruoyi.bus.domain.BusAlert;
import com.ruoyi.bus.service.IBusAlertService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2021-09-08
 */
@Controller
@RequestMapping("/bus/alert")
public class BusAlertController extends BaseController
{
    private String prefix = "bus/alert";

    @Autowired
    private IBusAlertService busAlertService;

    @RequiresPermissions("bus:alert:view")
    @GetMapping()
    public String alert()
    {
        return prefix + "/alert";
    }
    @RequiresPermissions("bus:alert:view")
    @GetMapping("send")
    public String send()
    {
        return prefix + "/send";
    }
    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("bus:alert:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusAlert busAlert)
    {
        startPage();
        List<BusAlert> list = busAlertService.selectBusAlertList(busAlert);
        return getDataTable(list);
    }
    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("bus:alert:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusAlert busAlert)
    {
        List<BusAlert> list = busAlertService.selectBusAlertList(busAlert);
        ExcelUtil<BusAlert> util = new ExcelUtil<BusAlert>(BusAlert.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("bus:alert:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusAlert busAlert)
    {
        return toAjax(busAlertService.insertBusAlert(busAlert));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BusAlert busAlert = busAlertService.selectBusAlertById(id);
        mmap.put("busAlert", busAlert);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("bus:alert:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusAlert busAlert)
    {
        return toAjax(busAlertService.updateBusAlert(busAlert));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("bus:alert:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(busAlertService.deleteBusAlertByIds(ids));
    }
}
